// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class CameraRenderTexture extends cc.Component {
    
    @property(cc.Camera)
    camera: cc.Camera = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.width = cc.winSize.width;
        this.node.height = cc.winSize.height;
        let sprite = this.getComponent(cc.Sprite);
        if (sprite == null) { return; }
        let texture = new cc.RenderTexture();
        texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height);
        this.camera.targetTexture = texture;
        let spriteFrame = new cc.SpriteFrame();
        spriteFrame.setTexture(texture);
        sprite.spriteFrame = spriteFrame;
    }

    // update (dt) {}
}
